package com.xuzz.study.spring.schema;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.w3c.dom.Element;

public class StudentBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
    protected  Class getBeanClass(Element element)
    {
        return Student.class;
    }


    @Override
    protected void doParse(Element element, BeanDefinitionBuilder builder) {
        String name = element.getAttribute("name");
        String age = element.getAttribute("age");

        if(StringUtils.isNotEmpty(name))
        {
            builder.addPropertyValue("name",name);
        }
        if(StringUtils.isNotEmpty(age))
        {
            builder.addPropertyValue("age",Integer.valueOf(age));
        }
    }
}
